package com.leadingsoft.pwxk.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.leadingsoft.pwxk.converter.AirPollutionOrgConverter;
import com.leadingsoft.pwxk.dto.AirPollutionOrgDto;
import com.leadingsoft.pwxk.model.AirPollutionOrg;
import com.leadingsoft.pwxk.model.DrainInfoAirOrgCountOne;
import com.leadingsoft.pwxk.model.DrainInfoAirOrgCountThr;
import com.leadingsoft.pwxk.model.DrainInfoAirOrgCountTwo;
import com.leadingsoft.pwxk.model.DrainInfoAirOrgTwo;
import com.leadingsoft.pwxk.repository.AirPollutionOrgRepository;
import com.leadingsoft.pwxk.service.AirPollutionOrgService;

@Service
public class AirPollutionOrgServiceImpl implements AirPollutionOrgService {

	@Autowired
	private AirPollutionOrgRepository airPollutionOrgRepository;
	@Autowired
	private AirPollutionOrgConverter airPollutionOrgConverster;

	@Override
	public AirPollutionOrgDto get(String dataid) {
		List<AirPollutionOrg> findByDataid = airPollutionOrgRepository.findByDataid(dataid);
		return airPollutionOrgConverster.toDto(findByDataid == null ? null : findByDataid.get(0));
	}

	@Override
	public List<AirPollutionOrgDto> findByDataId(String dataid) {
		return airPollutionOrgConverster.toDto(airPollutionOrgRepository.findByDataid(dataid));
	}

	@Cacheable(cacheNames = "airPo", sync = true)
	@Override
	public AirPollutionOrg findById(Long id) {
		AirPollutionOrg one = airPollutionOrgRepository.findById(id).get();
		return one;

	}

}
